package ar.edu.itba.pod.legajo46470.statistics;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;

import ar.edu.itba.node.api.NodeStatistics;
import ar.edu.itba.node.api.StatisticReports;
import ar.edu.itba.pod.agent.market.AgentState;
import ar.edu.itba.pod.agent.runner.Agent;
import ar.edu.itba.pod.legajo46470.simulation.DistributedSimulation;

public class DistributedStatistics extends UnicastRemoteObject implements
		StatisticReports {
	private static final long serialVersionUID = 5254523782925123904L;
	private DistributedSimulation simulation;

	public DistributedStatistics(DistributedSimulation simulation)
			throws RemoteException {
		super();
		this.simulation = simulation;
	}

	@Override
	public NodeStatistics getNodeStatistics() throws RemoteException {
		List<AgentState> agentStates = new ArrayList<AgentState>();

		for (Agent a : simulation.getAgentsRunning()) {
			agentStates.add(a.state());
		}

		return new NodeStatistics(simulation.getAgentsRunning().size(),
				agentStates);
	}
}